---@class EMOUtility
local EMO = {}

-- 用于存放一些函数
-- 使用时在扩展开头加一句 local EMO = require "packages.moepack.utility.emo_util"


-- 在指定范围选择一个数字
---@param player ServerPlayer @ 角色
---@param min integer @ 最小值
---@param max integer @ 最大值
---@param prompt? string @ 提示
---@param cancelable? boolean @ 可以取消吗？默认可
---@return integer?
EMO.chooseNum = function (player, min, max, prompt, cancelable)
  if cancelable == nil then cancelable = true end
  local _, dat = player.room:askToUseActiveSkill(player, {
    skill_name = "emo__choose_num", cancelable = cancelable, prompt = prompt,
    extra_data = {min = min, max = max},
  })
  if dat then
    return dat.interaction
  elseif not cancelable then
    return min
  end
  return nil
end

-- 切换皮肤，可单向或双向切换
---@param player ServerPlayer @ 角色
---@param general1 string @ 来源皮肤
---@param general2 string @ 目标皮肤
---@param loop? boolean @ 是否双向切换，默认单向
---@return boolean? @ 是否成功切换
EMO.changeSkin = function (player, general1, general2, loop)
  local room = player.room
  if Fk.generals[general1] == nil or Fk.generals[general2] == nil then return false end
  local ret = false
  if player.general == general1 then
    room:setPlayerProperty(player, "general", general2)
    ret = true
  end
  if player.deputyGeneral == general1 then
    room:setPlayerProperty(player, "deputyGeneral", general2)
    ret = true
  end
  if ret or not loop then return ret end
  if player.general == general2 then
    room:setPlayerProperty(player, "general", general1)
    ret = true
  end
  if player.deputyGeneral == general2 then
    room:setPlayerProperty(player, "deputyGeneral", general1)
    ret = true
  end
  return ret
end

return EMO
